package com.bilibili.server.controller;

import com.bilibili.model.vo.MovementVo;
import com.bilibili.model.vo.MovementsVo;
import com.bilibili.model.vo.PageResult;
import com.bilibili.model.vo.VisitorsVo;
import com.bilibili.server.service.MovementService;
import com.bilibili.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * @author HuangRongFu
 * 2021/11/21 星期日10:49 上午
 */

@RestController
@RequestMapping("/movements")
public class MovementController {

    @Autowired
    private MovementService movementService;


    /**
     * 发布动态
     *
     * @param: vo
     * @param: imageContent
     * @Return: ResponseEntity
     */
    @PostMapping
    public ResponseEntity Movements(MovementVo vo, MultipartFile[] imageContent) {

        movementService.PostMovement(vo, imageContent);

        return ResponseEntity.ok(null);
    }

    /**
     * 查询用户
     *
     * @param: page
     * @param: pageSize
     * @param: userId
     * @Return: ResponseEntity
     */
    @GetMapping("/all")
    public ResponseEntity findByUserId(@RequestParam(value = "page", defaultValue = "1") Long page,
                                       @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize,
                                       Long userId) {

        PageResult<MovementsVo> pageResult = movementService.findByUserId(page, pageSize, userId);

        return ResponseEntity.ok(pageResult);
    }

    /**
     * 好友动态
     * @param:  page
     * @param:  pageSize
     * @Return: ResponseEntity
     */
    @GetMapping
    public ResponseEntity findFriendMovement(@RequestParam(value = "page", defaultValue = "1") Long page,
                                             @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize){

        PageResult<MovementsVo> pageResult = movementService.findFriendMovement(page, pageSize);

        return ResponseEntity.ok(pageResult);
    }

    /**
     * 推荐动态
     * @param  page
     * @param  pageSize
     * @Return: ResponseEntity
     */
    @GetMapping("/recommend")
    public ResponseEntity recommend(@RequestParam(value = "page", defaultValue = "1") Long page,
                                    @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize){

        PageResult<MovementsVo> pageResult = movementService.findRecommend(page, pageSize);

        return ResponseEntity.ok(pageResult);
    }

    /**
     * 查询单条动态
     */
    @GetMapping("/{id}")
    public ResponseEntity findById(@PathVariable("id") String movementId){

        MovementsVo vo = movementService.findById(movementId);

        return ResponseEntity.ok(vo);
    }

    /**
     * 动态 点赞
     * @param:  movementId
     * @Return: ResponseEntity
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id")String movementId) {

        Integer likeCount =  movementService.like(movementId);

        return ResponseEntity.ok(likeCount);
    }

    /**
     * 动态 取消点赞
     * @param  movementId
     * @Return: ResponseEntity
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id")String movementId) {

        Integer likeCount =  movementService.dislike(movementId);

        return ResponseEntity.ok(likeCount);
    }

    /**
     * 动态 喜欢
     * @param  movementId
     * @Return: ResponseEntity
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id")String movementId) {

        Integer likeCount =  movementService.love(movementId);

        return ResponseEntity.ok(likeCount);
    }

    /**
     * 动态 取消点赞
     * @param:  movementId
     * @Return: ResponseEntity
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id")String movementId) {

        Integer likeCount =  movementService.unlove(movementId);

        return ResponseEntity.ok(likeCount);
    }

    /**
     * 首页谁看过我
     *
     * @Return: ResponseEntity
     */
    @GetMapping("/visitors")
    public ResponseEntity visitors(){

        List<VisitorsVo> list = movementService.queryVisitorsList();

        return ResponseEntity.ok(list);
    }
}
